package com.mpsc.current.controller;


import com.mpsc.current.vo.KtyTaskDto;
import org.springframework.web.bind.annotation.*;

import java.io.BufferedReader;
import java.io.InputStreamReader;

@RestController
@RequestMapping("/ktyTask")
public class KtyTaskController {

    @PostMapping(value = "/queryList")
    public String queryList(@RequestBody KtyTaskDto ktyTaskDto) {
        System.out.println(ktyTaskDto.toString());

        return "接收成功";

    }

    /**
     * 参数异常检测
     *
     * @param oldPath
     * @param newPath
     * @return
     */
    @GetMapping(value = "/dm/parameters_active/mv")
    public void getParametersActive(@RequestParam("oldPath") String oldPath, @RequestParam("newPath") String newPath) {
        System.out.println("/dm/parameters_active/mv:" + oldPath + ":" + newPath);
        try {

            BufferedReader reader = null;
            String cmd = "mv " + oldPath + " " + newPath;
            Process process = Runtime.getRuntime().exec(new String[]{"sh", "-c", cmd});
            reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                System.out.println("***   " + line);
            }
            process.waitFor();
            process.destroy();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
